feat(cache): prune expired entries on startup#8
feat(cache): prune expired entries on startup#8silicon-intern wants to merge 1 commit intoggonzalez94:mainfrom
Conversation
Add a Prune() method to cache.Store that deletes rows where created_at + ttl_seconds < now. Called automatically during Open() to prevent unbounded cache growth. Closes ggonzalez94#5
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: adad6e060a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return nil | ||
| } | ||
| nowUnix := time.Now().UTC().Unix() | ||
| _, err := s.db.Exec("DELETE FROM cache_entries WHERE created_at + ttl_seconds < ?", nowUnix) |
There was a problem hiding this comment.
Preserve stale fallback window when pruning cache rows
runCachedCommand intentionally serves expired entries during temporary provider failures when they are within max_stale, but this delete condition removes rows immediately after TTL (created_at + ttl_seconds < now) during every Open() call. Because the CLI is typically a new process per command, entries that should be valid for stale fallback are deleted before the provider fetch path runs, so users lose the documented TTL+max-stale recovery behavior and see hard failures instead of stale fallback.
Useful? React with 👍 / 👎.
What
Adds a
Prune()method tocache.Storethat deletes all rows wherecreated_at + ttl_seconds < now(). It is called automatically duringOpen()so that every CLI invocation cleans up stale data before proceeding.Why
The cache currently grows indefinitely — entries are written with TTL metadata but never deleted. For agents or scripts calling the CLI frequently,
cache.dbaccumulates stale rows without bound.Changes
internal/cache/cache.go: AddPrune()method; call it inOpen()internal/cache/cache_test.go: AddTestPruneRemovesExpiredEntriesCloses #5